package siga.visao_academico;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import siga.banco.conexao;
import siga.navegadores.navegador;
import siga.visao_busca.buscaTurma;
import siga.visao.index;
import siga.visao.verErros;


public class GestaoMatricular extends javax.swing.JInternalFrame {
    Object[] JOopcoes = {"Sim","Não"};
    boolean ver = true;
    List cod_disc = new ArrayList();
    public GestaoMatricular() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpPMtricula = new javax.swing.JPanel();
        jSplitPane1 = new javax.swing.JSplitPane();
        jpPAcad = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtAcademico = new javax.swing.JTable();
        jToolBar2 = new javax.swing.JToolBar();
        jButton1 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jbFinanceiro = new javax.swing.JButton();
        jbVer = new javax.swing.JButton();
        jppDisiciplinas = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtDisciplina = new javax.swing.JTable();
        jToolBar3 = new javax.swing.JToolBar();
        jButton9 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtfTurma = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtfFase = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtfQtdMat = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setTitle("Matrículas Acadêmicas");
        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/obs_editar_16x16.png"))); // NOI18N
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosed(evt);
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameOpened(evt);
            }
        });

        jpPMtricula.setName("jpPMtricula"); // NOI18N

        jSplitPane1.setDividerLocation(400);
        jSplitPane1.setName("jSplitPane1"); // NOI18N

        jpPAcad.setBorder(javax.swing.BorderFactory.createTitledBorder("Acadêmicos"));
        jpPAcad.setName("jpPAcad"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jtAcademico.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Nome", "Situação"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtAcademico.setName("jtAcademico"); // NOI18N
        jtAcademico.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtAcademicoMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jtAcademico);
        jtAcademico.getColumnModel().getColumn(0).setPreferredWidth(100);
        jtAcademico.getColumnModel().getColumn(0).setMaxWidth(100);
        jtAcademico.getColumnModel().getColumn(2).setPreferredWidth(80);
        jtAcademico.getColumnModel().getColumn(2).setMaxWidth(80);

        jToolBar2.setFloatable(false);
        jToolBar2.setRollover(true);
        jToolBar2.setName("jToolBar2"); // NOI18N

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/aluno_adicionar.png"))); // NOI18N
        jButton1.setToolTipText("Matrícula");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar2.add(jButton1);

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/aluno_remover.png"))); // NOI18N
        jButton7.setToolTipText("Desmatrícular");
        jButton7.setName("jButton7"); // NOI18N
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        jToolBar2.add(jButton7);

        jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/aluno_rematricula.png"))); // NOI18N
        jButton10.setToolTipText("Rematrícular");
        jButton10.setName("jButton10"); // NOI18N
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });
        jToolBar2.add(jButton10);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/aluno_cancelar.png"))); // NOI18N
        jButton4.setToolTipText("Cancelar Matrícula");
        jButton4.setName("jButton4"); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jToolBar2.add(jButton4);

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/aluno_tranferencia.png"))); // NOI18N
        jButton5.setToolTipText("Transferencia");
        jButton5.setMargin(new java.awt.Insets(1, 1, 1, 1));
        jButton5.setName("jButton5"); // NOI18N
        jToolBar2.add(jButton5);

        jbFinanceiro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/aluno_financeiro.png"))); // NOI18N
        jbFinanceiro.setToolTipText("Gerar Financeiro");
        jbFinanceiro.setName("jbFinanceiro"); // NOI18N
        jbFinanceiro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbFinanceiroActionPerformed(evt);
            }
        });
        jToolBar2.add(jbFinanceiro);

        jbVer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/aluno_ver.png"))); // NOI18N
        jbVer.setToolTipText("Ver Todos os Acadêmicos que já foram matrículados nesta Turma");
        jbVer.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jbVer.setName("jbVer"); // NOI18N
        jbVer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbVerActionPerformed(evt);
            }
        });
        jToolBar2.add(jbVer);

        javax.swing.GroupLayout jpPAcadLayout = new javax.swing.GroupLayout(jpPAcad);
        jpPAcad.setLayout(jpPAcadLayout);
        jpPAcadLayout.setHorizontalGroup(
            jpPAcadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)
        );
        jpPAcadLayout.setVerticalGroup(
            jpPAcadLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpPAcadLayout.createSequentialGroup()
                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE))
        );

        jSplitPane1.setTopComponent(jpPAcad);

        jppDisiciplinas.setBorder(javax.swing.BorderFactory.createTitledBorder("Disciplinas"));
        jppDisiciplinas.setName("jppDisiciplinas"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jtDisciplina.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "F", "Disciplinas", "Prof. Titular", "Freq.(%)", "Média", "Recup.", "Méd. Final", "Sit."
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtDisciplina.setEnabled(false);
        jtDisciplina.setName("jtDisciplina"); // NOI18N
        jScrollPane2.setViewportView(jtDisciplina);
        jtDisciplina.getColumnModel().getColumn(0).setPreferredWidth(20);
        jtDisciplina.getColumnModel().getColumn(0).setMaxWidth(20);
        jtDisciplina.getColumnModel().getColumn(2).setPreferredWidth(250);
        jtDisciplina.getColumnModel().getColumn(2).setMaxWidth(250);
        jtDisciplina.getColumnModel().getColumn(3).setPreferredWidth(60);
        jtDisciplina.getColumnModel().getColumn(3).setMaxWidth(60);
        jtDisciplina.getColumnModel().getColumn(4).setPreferredWidth(50);
        jtDisciplina.getColumnModel().getColumn(4).setMaxWidth(50);
        jtDisciplina.getColumnModel().getColumn(5).setPreferredWidth(60);
        jtDisciplina.getColumnModel().getColumn(5).setMaxWidth(60);
        jtDisciplina.getColumnModel().getColumn(6).setPreferredWidth(70);
        jtDisciplina.getColumnModel().getColumn(6).setMaxWidth(70);
        jtDisciplina.getColumnModel().getColumn(7).setPreferredWidth(100);
        jtDisciplina.getColumnModel().getColumn(7).setMaxWidth(100);

        jToolBar3.setFloatable(false);
        jToolBar3.setRollover(true);
        jToolBar3.setName("jToolBar3"); // NOI18N

        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/disciplina_add.png"))); // NOI18N
        jButton9.setToolTipText("Inserir Disciplina");
        jButton9.setEnabled(false);
        jButton9.setName("jButton9"); // NOI18N
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });
        jToolBar3.add(jButton9);

        jButton11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/disciplina_remove.png"))); // NOI18N
        jButton11.setToolTipText("Remover Disciplina");
        jButton11.setEnabled(false);
        jButton11.setName("jButton11"); // NOI18N
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });
        jToolBar3.add(jButton11);

        jButton14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/situacao.png"))); // NOI18N
        jButton14.setToolTipText("Situação");
        jButton14.setEnabled(false);
        jButton14.setName("jButton14"); // NOI18N
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });
        jToolBar3.add(jButton14);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/sair_16x16.png"))); // NOI18N
        jButton2.setToolTipText("Finalizar");
        jButton2.setEnabled(false);
        jButton2.setFocusable(false);
        jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton2.setName("jButton2"); // NOI18N
        jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jToolBar3.add(jButton2);

        javax.swing.GroupLayout jppDisiciplinasLayout = new javax.swing.GroupLayout(jppDisiciplinas);
        jppDisiciplinas.setLayout(jppDisiciplinasLayout);
        jppDisiciplinasLayout.setHorizontalGroup(
            jppDisiciplinasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar3, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
        );
        jppDisiciplinasLayout.setVerticalGroup(
            jppDisiciplinasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jppDisiciplinasLayout.createSequentialGroup()
                .addComponent(jToolBar3, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE))
        );

        jSplitPane1.setRightComponent(jppDisiciplinas);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados da Turma"));
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setText("Turma:");
        jLabel1.setName("jLabel1"); // NOI18N

        jtfTurma.setEditable(false);
        jtfTurma.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jtfTurma.setName("jtfTurma"); // NOI18N

        jLabel2.setText("Fase:");
        jLabel2.setName("jLabel2"); // NOI18N

        jtfFase.setEditable(false);
        jtfFase.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jtfFase.setName("jtfFase"); // NOI18N

        jLabel3.setText("Qtd. de Acad. Mat.:");
        jLabel3.setName("jLabel3"); // NOI18N

        jtfQtdMat.setEditable(false);
        jtfQtdMat.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jtfQtdMat.setName("jtfQtdMat"); // NOI18N

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/siga/imagem/busca_16x16.png"))); // NOI18N
        jButton3.setToolTipText("Busca somente Turma");
        jButton3.setFocusable(false);
        jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton3.setMargin(new java.awt.Insets(1, 1, 1, 1));
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfTurma, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfFase, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtfQtdMat, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton3)
                .addContainerGap(197, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton3)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2)
                        .addComponent(jtfFase, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jtfTurma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)
                        .addComponent(jtfQtdMat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jpPMtriculaLayout = new javax.swing.GroupLayout(jpPMtricula);
        jpPMtricula.setLayout(jpPMtriculaLayout);
        jpPMtriculaLayout.setHorizontalGroup(
            jpPMtriculaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 749, Short.MAX_VALUE)
        );
        jpPMtriculaLayout.setVerticalGroup(
            jpPMtriculaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpPMtriculaLayout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpPMtricula, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jpPMtricula, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        buscaTurma bt = new buscaTurma(null,true);
        bt.setLocation((index.tela.width-bt.getWidth())/2, (index.tela.height-bt.getHeight())/2);
        bt.setVisible(true);
        if(buscaTurma.isConfirmaTurma()){
            jtfTurma.setText(index.LRturma.get(0).toString());
            jtfFase.setText(index.LRfase.get(0).toString());
            geraTableAcademico();
        }
        index.LRturma.add(0, "");
        index.LRfase.add(0, "");
        index.LRturma.add(1, "");
        index.LRfase.add(1, "");
}//GEN-LAST:event_jButton3ActionPerformed

    private void formInternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosed

    }//GEN-LAST:event_formInternalFrameClosed

    private void formInternalFrameOpened(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameOpened

    }//GEN-LAST:event_formInternalFrameOpened

    private void jtAcademicoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtAcademicoMouseClicked
        if(evt.getClickCount()==2){
            jtAcademico.setEnabled(false);
            jButton1.setEnabled(false);
            jButton7.setEnabled(false);
            jButton10.setEnabled(false);
            jButton4.setEnabled(false);
            jButton5.setEnabled(false);
            jbFinanceiro.setEnabled(false);
            jbVer.setEnabled(false);

            jtDisciplina.setEnabled(true);
            jButton9.setEnabled(true);
            jButton11.setEnabled(true);
            jButton14.setEnabled(true);
            jButton2.setEnabled(true);
            index.LRpessoa.clear();
            geraTableDisciplina();
        }
    }//GEN-LAST:event_jtAcademicoMouseClicked

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        GestaoMatricular_insMatricula gmim = new GestaoMatricular_insMatricula(null,true);
        gmim.setLocation((index.tela.width-gmim.getWidth())/2, (index.tela.height-gmim.getHeight())/2);
        gmim.setVisible(true);
        if(jtAcademico.getSelectedRowCount()>0){
            javax.swing.table.DefaultTableModel jta = (javax.swing.table.DefaultTableModel) jtAcademico.getModel();
            index.LRpessoa.add(0,jta.getValueAt(jtAcademico.getSelectedRow(), 0).toString());
            index.LRpessoa.add(1,jta.getValueAt(jtAcademico.getSelectedRow(), 1).toString());
        }else{
            index.LRpessoa.clear();
        }
        if(gmim.matricula){
            geraTableAcademico();
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        if(!jtfTurma.getText().equals("")){
            if(jtAcademico.getSelectedRowCount()>0){
                javax.swing.table.DefaultTableModel jta = (javax.swing.table.DefaultTableModel) jtAcademico.getModel();
                if (JOptionPane.showOptionDialog(null, "Deseja desmatricular o acadêmico "+jta.getValueAt(jtAcademico.getSelectedRow(), 1)+"?\nEsta ação implica em remover o Acadêmico, Disciplinas e Financeiro.", "Desmatriculando", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, JOopcoes, JOopcoes[0]) == JOptionPane.YES_OPTION) {
                    conexao.Inserir("delete from diario where cod_emp="+index.cod_emp+" and cod_pessoa="+jta.getValueAt(jtAcademico.getSelectedRow(), 0)+" and cod_matricula=\""+jtfTurma.getText()+"\"");
                    conexao.Inserir("delete from fin_contas_mov_r where cod_emp="+index.cod_emp+" and cod_pessoa="+jta.getValueAt(jtAcademico.getSelectedRow(), 0)+" and cod_matricula=\""+jtfTurma.getText()+"\"");
                    JOptionPane.showMessageDialog(null, "Acadêmico "+jta.getValueAt(jtAcademico.getSelectedRow(), 1)+" esta desmatrículado.","Desmatriculando",JOptionPane.INFORMATION_MESSAGE);
                    geraTableAcademico();
                }
            }else{
                JOptionPane.showMessageDialog(null, "A seleção de um Acadêmico é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
            }
        }else{
           JOptionPane.showMessageDialog(null, "A seleção de uma Turma é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jbVerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbVerActionPerformed
        ver=!ver;
        geraTableAcademico();
    }//GEN-LAST:event_jbVerActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        if(!jtfTurma.getText().equals("")){
            if(jtAcademico.getSelectedRowCount()>0){
               javax.swing.table.DefaultTableModel jta = (javax.swing.table.DefaultTableModel) jtAcademico.getModel();
               if (JOptionPane.showOptionDialog(null, "Deseja rematricular o acadêmico "+jta.getValueAt(jtAcademico.getSelectedRow(), 1)+"?\nEsta ação irá rematricular o Acadêmido porém não será gerado o financeiro do mesmo.", "Rematriculando", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, JOopcoes, JOopcoes[0]) == JOptionPane.YES_OPTION) {
                    conexao.Inserir("update diario set cod_situacao=1, dt_cancelamento=now() where cod_emp="+index.cod_emp+" and cod_matricula=\""+jtfTurma.getText()+"\" and cod_fase="+jtfFase.getText()+" and cod_pessoa="+jta.getValueAt(jtAcademico.getSelectedRow(),0));
                    JOptionPane.showMessageDialog(null, "Rematrícula efetuada.","Rematricula.",JOptionPane.INFORMATION_MESSAGE);
                    geraTableAcademico();
               }
            }else{
                JOptionPane.showMessageDialog(null, "A seleção de um Acadêmico é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
            }
        }else{
            JOptionPane.showMessageDialog(null, "A seleção de uma Turma é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jButton10ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        if(!jtfTurma.getText().equals("")){
            if(jtAcademico.getSelectedRowCount()>0){
               javax.swing.table.DefaultTableModel jta = (javax.swing.table.DefaultTableModel) jtAcademico.getModel();
               if (JOptionPane.showOptionDialog(null, "Deseja cancelar a matrícula do acadêmico "+jta.getValueAt(jtAcademico.getSelectedRow(), 1)+"?\nEsta ação irá cancelar a matrícula do Acadêmido.", "Cancelando Matrícula", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, JOopcoes, JOopcoes[0]) == JOptionPane.YES_OPTION) {
                    conexao.Inserir("update diario set cod_situacao=8, dt_cancelamento=now() where cod_emp="+index.cod_emp+" and cod_matricula=\""+jtfTurma.getText()+"\" and cod_fase="+jtfFase.getText()+" and cod_pessoa="+jta.getValueAt(jtAcademico.getSelectedRow(),0));
                    conexao.Inserir("insert into fin_obs(cod_emp,descricao,cod_usuario, data, cod_pessoa) values("+index.cod_emp+",\"Aluno cancelou sua Matrícula.\",1,now(),"+index.usuario[0]+")");
                    JOptionPane.showMessageDialog(null, "Cancelamento da Matrícula efetuada.","Matrícula Cancelada.",JOptionPane.INFORMATION_MESSAGE);
                    geraTableAcademico();
               }
            }else{
                JOptionPane.showMessageDialog(null, "A seleção de um Acadêmico é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
            }
        }else{
            JOptionPane.showMessageDialog(null, "A seleção de uma Turma é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jbFinanceiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbFinanceiroActionPerformed
        if(!jtfTurma.getText().equals("")){
            if(jtAcademico.getSelectedRowCount()>0){
                GestaoMatricular_insFinanceiro gmif = new GestaoMatricular_insFinanceiro(null,true);
                gmif.setLocation((index.tela.width-gmif.getWidth())/2, (index.tela.height-gmif.getHeight())/2);
                index.LRturma.add(0, jtfTurma.getText());
                javax.swing.table.DefaultTableModel jta = (javax.swing.table.DefaultTableModel) jtAcademico.getModel();
                index.LRpessoa.add(0, jta.getValueAt(jtAcademico.getSelectedRow(), 0).toString());
                index.LRpessoa.add(1, jta.getValueAt(jtAcademico.getSelectedRow(), 1).toString());
                gmif.setVisible(true);
                if(gmif.financeiro){
                    geraTableAcademico();
                }
                index.LRturma.clear();
            }else{
                JOptionPane.showMessageDialog(null, "A seleção de um Acadêmico é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
            }
        }else{
            JOptionPane.showMessageDialog(null, "A seleção de uma Turma é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jbFinanceiroActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        if(!jtfTurma.getText().equals("")){
            if(jtAcademico.getSelectedRowCount()>0){
                GestaoMatricular_insDisciplina gmid = new GestaoMatricular_insDisciplina(null,true);
                gmid.setLocation((index.tela.width-gmid.getWidth())/2, (index.tela.height-gmid.getHeight())/2);
                index.LRturma.add(0,jtfTurma.getText());
                index.LRfase.add(0,jtfFase.getText());
                gmid.setVisible(true);
                if(gmid.disciplia){
                    geraTableDisciplina();
                }
                index.LRpessoa.clear();
                index.LRturma.clear();
                index.LRfase.clear();
            }else{
                JOptionPane.showMessageDialog(null, "A seleção de um Acadêmico é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
            }
        }else{
            JOptionPane.showMessageDialog(null, "A seleção de uma Turma é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        javax.swing.table.DefaultTableModel jtd = (javax.swing.table.DefaultTableModel) jtDisciplina.getModel();
        if (JOptionPane.showOptionDialog(null, "Deseja remover a disciplina "+jtd.getValueAt(jtDisciplina.getSelectedRow(), 1)+"?", "Removendo Disciplina", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, JOopcoes, JOopcoes[0]) == JOptionPane.YES_OPTION) {
            javax.swing.table.DefaultTableModel jta = (javax.swing.table.DefaultTableModel) jtAcademico.getModel();
            if(jtDisciplina.getSelectedRow()>0){
                if(jtd.getValueAt(jtDisciplina.getSelectedRow(), 4)==null){
                    conexao.Inserir("delete from diario where cod_emp="+index.cod_emp+" and cod_pessoa="+index.LRpessoa.get(0)+" and cod_matricula=\""+jtfTurma.getText()+"\" and cod_fase="+jtfFase.getText()+" and cod_disciplina="+cod_disc.get(jtDisciplina.getSelectedRow()));
                    JOptionPane.showMessageDialog(null, "Disciplina removida.","Removendo Disciplina",JOptionPane.INFORMATION_MESSAGE);
                    geraTableDisciplina();
                }else{
                    JOptionPane.showMessageDialog(null, "Esta disciplina já possui Aulas e não pode ser Removida.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
                }
            }else{
                JOptionPane.showMessageDialog(null, "A seleção de uma Disciplina é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
            }
        }
    }//GEN-LAST:event_jButton11ActionPerformed

    @SuppressWarnings("static-access")
    private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
        javax.swing.table.DefaultTableModel jtd = (javax.swing.table.DefaultTableModel)jtDisciplina.getModel();
        if(!cod_disc.get(jtDisciplina.getSelectedRow()).equals("")){
            GestaoMatricular_altSituacao gmas = new GestaoMatricular_altSituacao(null,true);
            gmas.setLocation((index.tela.width-gmas.getWidth())/2, (index.tela.height-gmas.getHeight())/2);
            gmas.gm_cod_acad = index.LRpessoa.get(0).toString();
            gmas.gm_cod_disciplina = cod_disc.get(jtDisciplina.getSelectedRow()).toString();
            gmas.gm_cod_turma = jtfTurma.getText();
            gmas.setVisible(true);
            if(gmas.gm_finaliza){
                geraTableDisciplina();
            }
        }else{
            JOptionPane.showMessageDialog(null, "A seleção de uma Disciplina é obrigatório.","Alerta do Sistema.",JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jButton14ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        
        jtAcademico.setEnabled(true);
        jButton1.setEnabled(true);
        jButton7.setEnabled(true);
        jButton10.setEnabled(true);
        jButton4.setEnabled(true);
        jButton5.setEnabled(true);
        jbFinanceiro.setEnabled(true);
        jbVer.setEnabled(true);
        
        jtDisciplina.setEnabled(false);
        jButton9.setEnabled(false);
        jButton11.setEnabled(false);
        jButton14.setEnabled(false);
        jButton2.setEnabled(false);
        index.LRpessoa.clear();
        
        javax.swing.table.DefaultTableModel jtd = (javax.swing.table.DefaultTableModel) jtDisciplina.getModel();
        for (int x = jtDisciplina.getRowCount() - 1; x >= 0; --x) {
            jtd.removeRow(x);
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void geraTableAcademico(){
        try {
            String Visao;
            if(ver){Visao=" and d.cod_situacao<>8 ";}else{Visao="";}
            conexao.Query("select p.codigo, p.descricao, d.cod_situacao, gs.sigla from diario d " +
                    " inner join pessoas p on p.codigo=d.cod_pessoa and p.cod_emp=d.cod_emp" + 
                    " inner join grade_situacao gs on gs.codigo=d.cod_situacao " +
                    " where d.cod_emp=" + index.cod_emp + Visao +" and d.cod_fase=" + jtfFase.getText() + " and d.cod_matricula=\"" + jtfTurma.getText() + "\" group by p.codigo order by p.descricao ");
            javax.swing.table.DefaultTableModel jta = (javax.swing.table.DefaultTableModel)jtAcademico.getModel();
            for (int x = jtAcademico.getRowCount() - 1; x >= 0; --x) {
                jta.removeRow(x);
            }
            javax.swing.table.DefaultTableModel jtd = (javax.swing.table.DefaultTableModel) jtDisciplina.getModel();
            for (int x = jtDisciplina.getRowCount() - 1; x >= 0; --x) {
                jtd.removeRow(x);
            }
            int conta=0;
            while (conexao.rs.next()) {
                if(conexao.rs.getInt("cod_situacao")!=8){conta++;}
                jta.addRow(new Object[]{conexao.rs.getString("codigo"),conexao.rs.getString("descricao"),conexao.rs.getString("sigla")});
            }
            jtfQtdMat.setText(""+conta);
        } catch (SQLException ex) {
            verErros.setErro(ex.getMessage());
        }
    }

    private void geraTableDisciplina(){
        try {
            javax.swing.table.DefaultTableModel jtd = (javax.swing.table.DefaultTableModel) jtDisciplina.getModel();
            javax.swing.table.DefaultTableModel jta = (javax.swing.table.DefaultTableModel) jtAcademico.getModel();
            index.LRpessoa.add(0,jta.getValueAt(jtAcademico.getSelectedRow(), 0).toString());
            index.LRpessoa.add(1,jta.getValueAt(jtAcademico.getSelectedRow(), 1).toString());
            cod_disc.removeAll(cod_disc);
            for (int x = jtDisciplina.getRowCount() - 1; x >= 0; --x) {
                jtd.removeRow(x);
            }
            conexao.Query("select d.*, p.descricao as des_prof, gd.descricao as des_disc, gs.descricao as situacao from diario d " +
                    " inner join grade_disciplina gd on gd.codigo=d.cod_disciplina and gd.cod_emp=d.cod_emp " +
                    " inner join grade_situacao gs on gs.codigo=d.cod_situacao " +
                    " left join pessoas p on p.codigo=d.cod_prof_t and p.cod_emp=d.cod_emp " +
                    " where d.cod_emp=" + index.cod_emp + " and d.cod_matricula=\"" + jtfTurma.getText() + "\" and d.cod_fase=" + jtfFase.getText() + " and d.cod_pessoa=" + jta.getValueAt(jtAcademico.getSelectedRow(), 0) + " group by d.cod_disciplina order by d.cod_fase,gd.descricao");
            while (conexao.rs.next()) {
                cod_disc.add(conexao.rs.getString("cod_disciplina"));
                jtd.addRow(new Object[]{conexao.rs.getString("cod_fase"),conexao.rs.getString("des_disc"),conexao.rs.getString("des_prof"),(conexao.rs.getString("frequencia")==null)?"":index.ftbr.format(conexao.rs.getDouble("frequencia")),(conexao.rs.getString("media")==null)?"":index.ftbr.format(conexao.rs.getDouble("media")),(conexao.rs.getString("recuperacao_nota")==null)?"":index.ftbr.format(conexao.rs.getDouble("recuperacao_nota")),(conexao.rs.getString("pre_media")==null)?(conexao.rs.getString("media")==null)?"":index.ftbr.format(conexao.rs.getDouble("media")):index.ftbr.format(conexao.rs.getDouble("pre_media")),conexao.rs.getString("situacao")});
            }
        } catch (SQLException ex) {
            verErros.setErro(ex.getMessage());
        }
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JToolBar jToolBar3;
    private javax.swing.JButton jbFinanceiro;
    private javax.swing.JButton jbVer;
    private javax.swing.JPanel jpPAcad;
    private javax.swing.JPanel jpPMtricula;
    private javax.swing.JPanel jppDisiciplinas;
    private javax.swing.JTable jtAcademico;
    private javax.swing.JTable jtDisciplina;
    private javax.swing.JTextField jtfFase;
    private javax.swing.JTextField jtfQtdMat;
    private javax.swing.JTextField jtfTurma;
    // End of variables declaration//GEN-END:variables

}
